/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @param {number[]} nums
 * @return {number}
 */

var numComponents = function (head, nums) {
  let p = head
  let count = 0
  while (p) {
    if(!nums.includes(p.val)){
      p = p.next
    }else {
      nums.splice(nums.indexOf(p.val),1)
      if(nums.length>0){
        p = p.next
      }
    }
  }
  p = p.next
  return count
}
